package cn.seocoo.platform.common.utils.jpush;

import cn.seocoo.platform.common.exception.BusinessException;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 消息通知状态
 * @author KongXianDe
 * @date 2018/12/25 17:58
 */
//@JSONType(serializeEnumAsJavaBean = true)
public enum MessageStatusEnum {
    /**
     * 收款成功
     */
    INCOME_SUCCESS(1, "收款成功"),
    /**
     * 退款成功
     */
    REFUND_SUCCESS(2, "退款成功"),
    /**
     * 退款失败
     */
    REFUND_FAILED(3, "退款失败"),
    /**
     * 订单完成
     */
    ORDER_FINISHED(4, "订单完成"),
    /**
     * 会员开通成功
     */
    OPEN_VIP(5, "会员开通成功"),
    /**
     * 会员开通成功
     */
    RENEWAL_VIP(6, "会员开通成功"),
    /**
     * 收到新的订单
     */
    NEW_ORDER(7, "收到新的订单"),
    /**
     * 余额支付成功
     */
    BALANCE_PAY_SUCCESS(8, "余额支付成功"),
    /**
     * 扫背面收款码收款
     */
    SCAN_QRCODE_PAY(9, "扫背面收款码收款");


   // NEW_SYSTEM_MESSAGE(10,"系统消息");

    /**
     * @Author WuJian
     * @Description
     * @Date 16:17 2019/7/26
     * @Param
     * @return
     **/

    private int code;
    private String desc;
    private String name;

    MessageStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private static final Map<Integer, MessageStatusEnum> BY_VALUE_MAP = new LinkedHashMap<>();

    static {
        for (MessageStatusEnum messageStatusEnum : MessageStatusEnum.values()) {
            BY_VALUE_MAP.put(messageStatusEnum.getCode(), messageStatusEnum);
        }
    }

    /**
     * 根据code查询对应的外卖类型枚举
     */
    public static MessageStatusEnum convertCode2Enum(int code) throws BusinessException {
        if (!BY_VALUE_MAP.containsKey(code)) {
            throw new BusinessException("枚举对应的code" + code + "不存在");
        }
        return BY_VALUE_MAP.get(code);
    }

    /**
     * 根据枚举name查询对应的外卖类型枚举
     */
    public static MessageStatusEnum convertStr2Enum(String str) throws BusinessException {
        try {
            return MessageStatusEnum.valueOf(str);
        } catch (Exception e) {
            throw new BusinessException("枚举对应常量" + str + "不存在");
        }
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getName() {
        return this.name();
    }
}
